<!--  -->
<template>
  <div class="app-container">
    <el-form :inline="true" size="small">
      <el-form-item label="角色名称">
        <el-input v-model="mId" placeholder="请输入分类编号" size="small"></el-input>
      </el-form-item>
      <el-form-item label="状态">
        <el-select v-model="mName" placeholder="角色状态" clearable filterable @change>
          <el-option label="正常" value="normal"></el-option>
          <el-option label="停用" value="stop"></el-option>
        </el-select>
      </el-form-item>

      <el-button icon="el-icon-search" type="primary" size="small" @click>搜索</el-button>
      <el-button icon="el-icon-refresh" size="small" @click>重置</el-button>
      <el-button icon="el-icon-edit" type="warning" size="small" @click="add()">新增</el-button>
      <el-button icon="el-icon-delete" type="danger" size="small" @click>删除</el-button>

      <el-button class="ref-btn" icon="el-icon-refresh" circle @click></el-button>
    </el-form>

    <el-table :data="tableData" border stripe>
      <el-table-column type="selection" width="60" align="center"></el-table-column>

      <template v-for="(i, index) in columns">
        <el-table-column
          v-if="index==2"
          :key="i.id"
          :label="i.label"
          align="center"
          :width="i.width"
        >
          <template slot-scope="scope">
            <el-switch v-model="scope.row.status" :active-value="1" :inactive-value="2" @change></el-switch>
          </template>
        </el-table-column>

        <el-table-column
          v-else
          :prop="i.data"
          :key="i.id"
          :label="i.label"
          align="center"
          :width="i.width"
        />
      </template>
      <el-table-column align="center" label="操作">
        <template slot-scope="scope">
          <el-button type="text" icon="el-icon-edit" @click="edit(scope.$index)">编辑</el-button>
          <el-button type="text" icon="el-icon-key" @click="edit(scope.$index)">数据权限</el-button>
          <el-button
            type="text"
            icon="el-icon-delete"
            style="color:#F56C6C"
            @click="del(scope.$index,scope.row)"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <div class="page">
      <el-pagination
        @size-change="sizeChange"
        @current-change="currentChange"
        :current-page.sync="page"
        :page-sizes="[20, 40, 80, 100]"
        :page-size="limit"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        background
      ></el-pagination>
    </div>

    <!-- 对话框 -->
    <el-dialog
      :title="dialogTitle"
      :visible.sync="showDialog"
      width="40%"
      @close="showDialog = false"
    >
      <el-form
        v-model="addForm"
        ref="add"
        :rules="rules"
        v-if="showAdd"
        label-width="120px"
        :inline="false"
        size="normal">
        <el-form-item label="角色编号" prop="id">
          <el-input v-model="addForm.id" :style="{width: '70%'}"></el-input>
        </el-form-item>
        <el-form-item label="角色名称" prop="name">
          <el-input v-model="addForm.name" :style="{width: '70%'}"></el-input>
        </el-form-item>
        <el-form-item label="状态" prop="status">
          <el-switch v-model="addForm.status" :active-value="1" :inactive-value="2" @change></el-switch>
        </el-form-item>
      </el-form>
      <span slot="footer">
        <el-button @click="showDialog = false">取消</el-button>
        <el-button type="primary" @click="submit()">确定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { getArticle } from "@/api/article";
export default {
  name: "slider",
  data() {
    return {
      mId: "",
      mName: "",
      keyword: "",
      page: 1,
      limit: 10,
      total: 10,
      dialogTitle: "新增",
      showDialog: false,
      showAdd: true,
      addForm: {
        id: "",
        name: "",
        status: true
      },
      tableData: [
        {
          id: "1",
          createTime: "2021-02-21 19:29:43",
          name: "系统管理员",
          status: 1
        },
        {
          id: "2",
          createTime: "2021-02-21 19:29:43",
          name: "普通管理员",
          status: 1
        },
        {
          id: "3",
          createTime: "2021-02-21 19:29:43",
          name: "门店管理员",
          status: 1
        }
      ],

      columns: [
        { key: 0, label: `角色编号`, data: "id", visible: true, width: 200 },
        { key: 1, label: `角色名称`, data: "name", visible: true },
        { key: 3, label: `状态`, data: "flag", visible: true, width: 140 },
        { key: 4, label: `创建时间`, data: "createTime", visible: true }
      ],
      rules: {
        id: [{ required: true, message: "请输入角色编号", trigger: "blur" }],
        name: [{ required: true, message: "请输入角色名称", trigger: "blur" }],
        status: [{ required: true, message: "", trigger: "blur" }]
      },

      artQuery: {
        id: "1"
      }
    };
  },
  created() {
    // getArticle();
  },
  methods: {
    add() {
      this.dialogTitle = "新增";
      this.addForm = {
        id: "",
        name: "",
        status: true
      };
      this.showDialog = true;
    },
    edit(i) {
      this.dialogTitle = "编辑信息";
      this.addForm = {
        id: this.tableData[i].id,
        name: this.tableData[i].name,
        status: this.tableData[i].status
      };
      this.showDialog = true;
    },
    del(i, d) {
      this.$confirm("确认删除所选数据？", "确认删除", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true
      })
        .then(() => {
          this.$message.warning("删除成功！");
          this.tableData.splice(i, 1);
        })
        .catch(() => {});
    },
    sizeChange() {},
    currentChange() {}
  }
};
</script>
<style scoped>
.slideImg {
  width: 140px;
}
</style>
